package com.chenyaowei.web.controller.product.sku;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chenyaowei.common.annotation.Log;
import com.chenyaowei.common.core.controller.BaseController;
import com.chenyaowei.common.core.domain.AjaxResult;
import com.chenyaowei.common.enums.BusinessType;
import com.chenyaowei.product.domain.CywProSkuImages;
import com.chenyaowei.product.service.ICywProSkuImagesService;
import com.chenyaowei.common.utils.poi.ExcelUtil;
import com.chenyaowei.common.core.page.TableDataInfo;

/**
 * sku图片集Controller
 *
 * @author 陈耀威
 * @date 2023-11-24
 */
@RestController
@RequestMapping("/product/skuImages")
public class CywProSkuImagesController extends BaseController
{
    @Autowired
    private ICywProSkuImagesService cywProSkuImagesService;

    @GetMapping("/list/{skuId}")
    public AjaxResult listBySkuId(@PathVariable("skuId") Long skuId)
    {
        List<CywProSkuImages> list = cywProSkuImagesService.selectListBySkuIds(Arrays.asList(skuId));
        return success(list);
    }

    /**
     * 查询sku图片集列表
     */
    @PreAuthorize("@ss.hasPermi('product:skuImages:list')")
    @GetMapping("/list")
    public TableDataInfo list(CywProSkuImages cywProSkuImages)
    {
        startPage();
        List<CywProSkuImages> list = cywProSkuImagesService.selectCywProSkuImagesList(cywProSkuImages);
        return getDataTable(list);
    }

    /**
     * 导出sku图片集列表
     */
    @PreAuthorize("@ss.hasPermi('product:skuImages:export')")
    @Log(title = "sku图片集", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CywProSkuImages cywProSkuImages)
    {
        List<CywProSkuImages> list = cywProSkuImagesService.selectCywProSkuImagesList(cywProSkuImages);
        ExcelUtil<CywProSkuImages> util = new ExcelUtil<CywProSkuImages>(CywProSkuImages.class);
        util.exportExcel(response, list, "sku图片集数据");
    }

    /**
     * 获取sku图片集详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:skuImages:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cywProSkuImagesService.selectCywProSkuImagesById(id));
    }

    /**
     * 新增sku图片集
     */
    @PreAuthorize("@ss.hasPermi('product:skuImages:add')")
    @Log(title = "sku图片集", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CywProSkuImages cywProSkuImages)
    {
        return toAjax(cywProSkuImagesService.insertCywProSkuImages(cywProSkuImages));
    }

    /**
     * 修改sku图片集
     */
    @PreAuthorize("@ss.hasPermi('product:skuImages:edit')")
    @Log(title = "sku图片集", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CywProSkuImages cywProSkuImages)
    {
        return toAjax(cywProSkuImagesService.updateCywProSkuImages(cywProSkuImages));
    }

    /**
     * 删除sku图片集
     */
    @PreAuthorize("@ss.hasPermi('product:skuImages:remove')")
    @Log(title = "sku图片集", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cywProSkuImagesService.deleteCywProSkuImagesByIds(ids));
    }
}
